﻿/*
 * Date：2023/3/1
 * Subject：产品分类控制器
 * 
 * **/
using Max.PH5_2008A.ShoppingCode.Domain;
using Max.PH5_2008A.ShoppingCode.IService;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Max.PH5_2008A.ShoppingCode.API.Controllers.Product
{
    /// <summary>
    /// 产品分类
    /// </summary>
    [Route("product/category")]
    [ApiController]
    public class ProductCategoryController : BaseController<TbProductCategory>
    {
        IProductCategoryService _service;
        public ProductCategoryController(IProductCategoryService service) : base(service)
        {
            _service = service;
        }

        /// <summary>
        /// 递归分类
        /// </summary>
        /// <returns></returns>
        [HttpGet("recuresion")]
        public IActionResult QueryRecuresion()
        {
            //参数需要一个id：
            var result = _service.RecuresionCategory("");

            return Ok(result);
        }

        #region 后台管理接口

        /// <summary>
        /// 后台管理的分类查询
        /// </summary>
        /// <param name="key"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet("admin/query")]
        public IActionResult Query(string? name,int pageIndex=1,int pageSize=8)
        {
            var data = _service.Query(name, pageIndex, pageSize, out int count);
            return Ok(new { items = data,total = count});
        }

        #endregion
    }
}
